//
//  latestNewsViewController.m
//  ExpressData
//
//  Created by Sun Thurein Aung on 16/02/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "LatestNewsViewController.h"


@implementation LatestNewsViewController

@synthesize myTableView, newsChoice;;
NSMutableArray *title;
NSMutableArray *subtitle;
NSMutableArray *edGram;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"background1.png"]];
	
	
	title = [[NSMutableArray alloc] init];
	
	[title addObject:@"ED iPhone App is now available"];
	[title addObject:@"ED to distribute IronPort Products"];
	
	subtitle = [[NSMutableArray alloc] init];
	
	[subtitle addObject:@"18 February 2011 9:56am"];
	[subtitle addObject:@"29 September 2010 4:30pm"];
	
	
	edGram = [[NSMutableArray alloc] init];
	
	[edGram addObject:@"February 2012 Issue"];
	[edGram addObject:@"Januaray 2011 Issue"];
	[edGram addObject:@"December 2010 Issue"];
	[edGram addObject:@"November 2010 Issue"];
	[edGram addObject:@"October 2010 Issue"];
//	myTableView.delegate = self;
	myTableView.backgroundColor = [UIColor clearColor];
}

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	if (newsChoice.selectedSegmentIndex == 0) {
		return [title count];
	}else {
		return[edGram count];
	}


}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return 84;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
	TDBadgedCell *cell = [[[TDBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    
		
	
	if (indexPath.row == 0) cell.badgeString =@"new";
	
	cell.badgeColor = [UIColor colorWithRed:1.000 green:0.397 blue:0.419 alpha:1.000];
	
	
	

	cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;	
	cell.textLabel.textColor = [UIColor blackColor];	
	cell.textLabel.font = [UIFont systemFontOfSize:14]; //Change this value to adjust size
	cell.textLabel.numberOfLines = 3; 		
	
	if (newsChoice.selectedSegmentIndex == 0) {
		
	
	NSString *cellvalue = [title objectAtIndex:indexPath.row];
	[cell.textLabel setText:cellvalue];
		

	[cell.detailTextLabel setText:[subtitle objectAtIndex:indexPath.row]];
	}else {
		[cell.textLabel setText:[edGram objectAtIndex:indexPath.row]];
		[cell.detailTextLabel setText:@""];
	}

//    NSString *cellIconName = @"bullet.png";
//    UIImage *cellIcon = [UIImage imageNamed:cellIconName];
//    [[cell imageView] setImage:cellIcon];
//	NSLog(@"%@",self.myTableView);
    return cell;
		
}

-(IBAction) segmentedControlIndexChanged {
//	NSLog(@"%@",self.myTableView);
	[self.myTableView reloadData];
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
	if (indexPath.row % 2)
	{
		
        [cell setBackgroundColor:[[UIColor alloc] initWithRed:220.0 / 255 green:220.0 / 255 blue:220.0 / 255 alpha:1.0]];
	}
	
	else         [cell setBackgroundColor:[[UIColor alloc] initWithRed:255.0 / 255 green:250.0 / 255 blue:240.0 / 255 alpha:1.0]];
}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return YES;
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
//	[myTableView release];
//	[newsChoice release];
//	[title release];
//	[subtitle release];
//	[edGram release];
}


@end
